package com.hulytu.android.hijack;

import android.content.Context;


import java.lang.reflect.Field;
import java.lang.reflect.Proxy;

/**
 * @author Chris (hulytu@163.com)
 * @date 2021/11/23
 */
public class AntiHijackUtils {

    private static final String SIGNATURE = BuildConfig.SIGNATURE;

    public static boolean checkSign(Context context) {
        if (context == null || isHookPMS()) return false;

        String modulus = Utils.getSignInfoNew(context);

        return SIGNATURE.equals(modulus);
    }


    public static boolean isHookPMS() {
        try {

            Class<?> clazz = Class.forName("android/app/ActivityThread");
            Field manager = clazz.getDeclaredField("sPackageManager");
            boolean accessible = manager.isAccessible();

            manager.setAccessible(true);
            Object obj = manager.get(null);
            manager.setAccessible(accessible);

            return obj == null || Proxy.class.isAssignableFrom(obj.getClass());
        } catch (Exception ignore) {

        }

        return true;
    }
}
